<?php
namespace app\shop\model;
use app\BaseModel;
use think\facade\Db;

class AdminShopBanner extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_shop_carousel';

   protected $append=[
       'company_text'
   ];

    /**
     * User: chenniang
     * Date: 2019-09-29 14:19
     * @param $value
     * @return void
     * descption:转换公司id array
     */
   public function getCIdAttr($value){
       $company_model = new AdminCompany();
       $dis[] = ['id','=',$value];
       $dis[] = ['status','>',-1];
       $dis[] = ['pid','=',0];
       return $company_model->where($dis)->value('id');
   }
    /**
     * User: chenniang
     * Date: 2019-09-11 11:50
     * @param $value
     * @param $data
     * @return void
     * descption:获取公司名字
     */
   public function getCompanyTextAttr($value,$data){
       $dis[]  = ['id','=',$data['c_id']];
       $dis[]  = ['status','>',-1];
       $comany = Db::name('longbing_card_company')->where($dis)->value('name');
       return $comany;
   }

    /**
     * User: chenniang
     * Date: 2019-09-11 12:01
     * @param $value
     * @return array|mixed
     * descption:转图片
     */
   public function getImgAttr($value){
        $img = transImagesOne([$value],[$value]);
        return is_array($img)?$img[0]:$img;
   }
    /**
     * @param $dis
     * @param int $page
     * @return mixed
     * 获取商城轮播图列表
     */
    public function bannerList($dis,$page=10){
        $data = self::where($dis)->order('top desc')->paginate($page)->toArray();
        return $data;
    }
    /**
     * @param $dis
     * @param $data
     * @return int
     * 修改商城轮播图
     */
    public function bannerUpdate($dis,$data){
        $data['update_time'] = time();
        $res = self::where($dis)->update($data);
        return $res;
    }

    /**
     * @param $data
     * 添加商城轮播图
     */
    public function bannerAdd($data){
        $data['create_time'] = time();
        $res = self::insert($data);
        return $res;
    }

    /**
     * @param $dis
     * 删除商城轮播图
     */

    public function bannerDel($dis){
        $res = self::where($dis)->update(['status'=>-1,'update_time'=>time()]);
        return $res;
    }

    /**
     * @param $dis
     * 轮播图详情
     */
    public function bannerInfo($dis){
       $data = self::where($dis)->find();
       return !empty($data)?$data->toArray():$data;
    }


}